package org.codeblue.support.time;

import java.io.Serializable;

/**
 * 时间间隔
 */
public class TimeSpan implements Serializable {
    private static final long serialVersionUID = 9073854012912530406L;

    private Long milliSeconds;

    public TimeSpan(Long milliSeconds) {
        this.milliSeconds = milliSeconds;
    }

    public Integer days() {
        return hours() / 24;
    }

    public Integer hours() {
        return (int) (minutes() / 60);
    }

    /**
     * 计算指定两个时间之间的相差分钟数。如果 this 晚于clockTime，则返回负值
     *
     * @return 分钟差
     */
    public Long minutes() {
        return seconds() / 60;
    }

    public Long seconds() {
        return milliSeconds() / 1000;
    }

    public Long milliSeconds() {
        return milliSeconds;
    }

    public String toString() {
        return super.toString() + ", " + milliSeconds() + "ms";
    }
}